package pri.hillchen.springbootstd.sso.common.util;

import org.apache.commons.lang.StringUtils;

import java.util.Collection;
import java.util.Map;

/**
 * Created by hillchen on 2017/8/11 0011.
 */
public class ObjectUtil {
    public static <T>boolean isEmpty(T obj){
        if(obj == null){
            return true;
        }
        if(obj instanceof String){
            return StringUtils.isBlank((String)obj);
        }
        if(obj instanceof Collection){
            return ((Collection)obj).isEmpty();
        }
        if (obj instanceof Map){
            return ((Map)obj).isEmpty();
        }
        if(obj.getClass().isArray() ){
            Object[] arrs = (Object[]) obj;
            return arrs.length == 0;
        }
        return true;
    }

    public static <T>T  emptyToDefVal(T obj,T def){
        return isEmpty(obj) ? def : obj;
    }


}
